package com.rpay.common.util;

import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Title：
 * Description
 *
 * @author fxg06 on 2018/5/6
 * @version 1.0
 */
public class JsoupUtil {
    public static JSONArray reptileByFeiXiaoHao() {
        JSONArray jsonArray = new JSONArray();
        Document doc = null;
        try {
            doc = Jsoup.connect("https://www.feixiaohao.com/coinmarket/ripple/").get();
            Element element = doc.selectFirst(".table3");
            Element childElement = element.selectFirst("tbody");
            Elements elements = childElement.select("tr");
            for (int i = 0; i < (elements.size() > 20 ? 20 : elements.size()); i++) {
                Element tempEle = elements.get(i);
                Elements tempEles = tempEle.select("td");
                JSONObject json = new JSONObject();
                json.put("index", tempEles.get(0).text());
                json.put("exchange", tempEles.get(1).text());
                json.put("transaction", tempEles.get(2).text());
                json.put("price", tempEles.get(3).text());
                json.put("quantity", tempEles.get(4).text());
                json.put("amount", tempEles.get(5).text());
                json.put("rate", tempEles.get(6).text());
                jsonArray.put(json);
            }
            return jsonArray;
        } catch (IOException e) {
            return null;
        }
    }

    public static void main(String[] args) {


    }
}
